/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pro.unal.edu.filter;

import java.awt.Color;

/**
 *
 * @author Carlos Eduardo Bernal Cárdenas
 * @version 1.0
 * @created 08-dic-2011
 */
public class MirrorFilter implements MyFilter {

    @Override
    public void doFilter(MyPoint[][] newImage, Color[][] colors) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public Color[][] doFilter(Color[][] actualImage) {
        Color[][] colors = new Color[actualImage.length][actualImage[0].length];
        for (int i = 0; i < actualImage.length - 1; i++) {
            for (int j = 0; j < actualImage[i].length - 1; j++) {
                if (actualImage[actualImage.length - 2 - i][j] != null) {
                    Color c = actualImage[actualImage.length - 2 - i][j];
                    int red = c.getRed();
                    int blue = c.getBlue();
                    int green = c.getGreen();
                    colors[actualImage.length - 2 - i][j] = actualImage[i][j];
                    colors[i][j] = new Color(red, green, blue);
                }
            }
        }
        return colors.clone();
    }

    public void printMatrix(Color[][] newImage) {
        for (int i = 0; i < newImage.length; i++) {
            for (int j = 0; j < newImage[0].length; j++) {
                if (newImage[i][j] != null) {
                    System.out.print(newImage[i][j] + " ");
                }
            }
            System.out.println("");
        }
    }

    public static void main(String[] args) {
        MirrorFilter m = new MirrorFilter();

        Color[][] c = {{Color.BLACK, Color.WHITE, Color.YELLOW}, {Color.CYAN, Color.GREEN, Color.ORANGE}};
        m.printMatrix(c);
        c = m.doFilter(c);
        m.printMatrix(c);
    }
}
